package com.fifth.apartment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fifth.apartment.constant.MessageConstant;
import com.fifth.apartment.entity.Housekeeper;
import com.fifth.apartment.result.PageResult;
import com.fifth.apartment.result.Result;
import com.fifth.apartment.service.HousekeeperService;
import com.fifth.apartment.vo.PageQueryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * TODO
 *
 * @author Dao
 * @since 2024/7/3
 */
//@RestController
//@RequestMapping("/admin/housekeeper")
//@Api(tags ="管家接口")
//@Slf4j
//public class HousekeeperController {
//
//    @Autowired
//    private HousekeeperService service;
//
//    @GetMapping("findPage")
//    @ApiOperation("条件查询每项信息")
//    public Result findPage(PageQueryVO vo) {
//log.info("条件查询每项信息:{}",vo);
//        Page<Housekeeper> page = service.findPage(vo);
//        if (page != null) {
//            PageResult newPage = new PageResult<>(page.getTotal(), page.getRecords());
//            return Result.success(newPage);
//        }
//        return null;
//
//    }
//
//}
@RestController
@RequestMapping("/admin/housekeeper")
@Api(tags = "管家接口")
@Slf4j
public class HousekeeperController {
    @Autowired
    private HousekeeperService service;

    @GetMapping("{id}")
    @ApiOperation("根据id查询管理员信息")
    public Result findById(@PathVariable("id") Integer id){
        try {
            Housekeeper housekeeper = service.getById(id);
            return new Result(true , MessageConstant.QUERY_CHECKITEM_SUCCESS , housekeeper);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(true , MessageConstant.QUERY_CHECKITEM_FAIL);
    }

    @GetMapping("/findPage")
    @ApiOperation("条件分页查询检查项信息")
    public Result findPage(PageQueryVO vo){
        try {
            Page<Housekeeper> page = service.findPage(vo);
            if(page!=null){
                return new Result(true , MessageConstant.QUERY_CHECKITEM_SUCCESS , page);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return new Result(true , MessageConstant.QUERY_CHECKITEM_FAIL);
    }

}

